//
//  YDYTabbarController.m
//  DYSisterAPP
//
//  Created by 杨德勇 on 16/7/26.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "YDYTabbarController.h"
#import "YDYTabBar.h"
#import "YDYEssenceViewController.h"
#import "YDYNewViewController.h"
#import "YDYFriendsViewController.h"
#import "YDYMeViewController.h"
#import "YDYNavigationController.h"
@interface YDYTabbarController ()


@end

@implementation YDYTabbarController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //加入子控制器
    [self addSubViewController];
    //设置tabbar：文字、颜色、大小
    [self setBarBtnItemState];
    //修改tabbar
    [self setValue:[[YDYTabBar alloc]init] forKey:@"tabBar"];
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    [self.view addSubview:self.poseBtn];
    
    
}



-(void)setBarBtnItemState{
    UITabBarItem *item = [UITabBarItem appearance];
    
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    [item setTitleTextAttributes:attrs forState:normal];
    
    
}
-(void)setupChildContrllerWithClass:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)image selectImgName:(NSString *)selectImg{
    
   
    
//在这里用了view的属性，会导致view过早加载，然后viewdidload方法里面加载顺序错了
//    vc.view.backgroundColor = YDYRandomColor;
    
    vc.tabBarItem.title = title;
    if (image.length) {
        vc.tabBarItem.image = [UIImage imageNamed:image];
    }
    if (selectImg.length) {
        vc.tabBarItem.selectedImage = [UIImage imageNamed:selectImg];
    }
    YDYNavigationController *nav = [[YDYNavigationController alloc]initWithRootViewController:vc];
    
    [self addChildViewController:nav];
}
//
-(void)addSubViewController{
    
  
    
    
    [self setupChildContrllerWithClass:[YDYEssenceViewController new] title:@"精华" imageName:@"tabBar_essence_icon" selectImgName:@"tabBar_essence_click_icon"];
    
    [self setupChildContrllerWithClass:[YDYNewViewController new] title:@"新帖" imageName:@"tabBar_new_icon" selectImgName:@"tabBar_new_click_icon"];
    [self setupChildContrllerWithClass:[YDYFriendsViewController new] title:@"关注" imageName:@"tabBar_friendTrends_icon" selectImgName:@"tabBar_friendTrends_click_icon"];
    [self setupChildContrllerWithClass:[YDYMeViewController new] title:@"我" imageName:@"tabBar_me_icon" selectImgName:@"tabBar_me_click_icon"];
   

    
}
@end
